package com.sk.bilibili.model.fragment.them;

import com.sk.api.annotations.Autowired;
import com.sk.bilibili.bean.Them;
import com.sk.bilibili.callBack.RequestCallBack;
import com.sk.bilibili.mapper.CoinMapper;
import com.sk.bilibili.mapper.FollowThemMapper;
import com.sk.bilibili.mapper.ThemMapper;
import com.sk.bilibili.mapper.VideoSetMapper;
import com.sk.bilibili.model.BaseRefreshModel;
import com.sk.bilibili.other.JsonMap;
import com.sk.bilibili.utils.RequestUtils;
import com.sk.bilibili.view.fragment.them.IntroductionFragment;

import java.util.List;

public class IntroductionModel extends BaseRefreshModel<IntroductionFragment> {

    @Autowired
    ThemMapper themMapper;
    @Autowired
    FollowThemMapper followThemMapper;
    @Autowired
    CoinMapper coinMapper;

    public void refreshData(Integer themId) {
        RequestUtils.process(themMapper.getThem(themId), them -> view.loadThemSuccess(them));
    }

    @Override
    public void refreshData() {
        RequestUtils.process(themMapper.getRandom(null, 20, 2), thems ->
                view.loadRecommendSuccess(thems));
    }

    public void followThem(Integer themId) {
        JsonMap map = new JsonMap();
        map.put("themId", themId);
        RequestUtils.process(followThemMapper.add(map),
                unused -> view.followThemSuccess());
    }

    public void addCoin(Integer themId) {
        JsonMap map = new JsonMap();
        map.put("num",2);
        map.put("type",1);
        map.put("targetId",themId);
        RequestUtils.process(coinMapper.addCoin(map), new RequestCallBack<Void>() {
            @Override
            public void success(Void unused) {
                view.addCoinSuccess();
            }
            @Override
            public void error(Throwable throwable) {
                view.addCoinError(throwable.getMessage());
            }
        });
    }

}